﻿using System;
namespace Producers.Ehr.Xtee.Riik.Ee.Producer.Ehr {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="EN_EhitiseOtsing_response", Namespace="http://producers.ehr.xtee.riik.ee/producer/ehr", Target=typeof(ENEhitiseOtsingResponse))]
    public class ENEhitiseOtsingResponseSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IENEhitiseOtsingResponse clazz;
        
        public ENEhitiseOtsingResponseSerializer(IENEhitiseOtsingResponse clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("EN_EhitiseOtsing");
            if (clazz.ENEhitiseOtsing!=null) {
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute(">>>EN_EhitiseOtsing_response>EN_EhitiseOtsing>ehitised", "http://producers.ehr.xtee.riik.ee/producer/ehr", clazz.ENEhitiseOtsing.Count);
                for (int x = 0; ((clazz.ENEhitiseOtsing != null) 
                            && (x < clazz.ENEhitiseOtsing.Count)); x = (x + 1)) {
                    if (clazz.ENEhitiseOtsing[x]!=null) {
                        Writer.WriteStartElement("ehitised");
                        global::Xtee.Core.SerializationMetadata metaENEhitiseOtsing = this.GetMetaData(clazz.ENEhitiseOtsing[x]);
                        Writer.WriteTypeAttribute(metaENEhitiseOtsing.TypeQualifiedName.Namespace, metaENEhitiseOtsing.TypeQualifiedName.Name);
                        metaENEhitiseOtsing.NewSerializer(clazz.ENEhitiseOtsing[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : ENEhitiseOtsing");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="EN_EhitiseOtsing") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>EN_EhitiseOtsing_response>EN_EhitiseOtsing");
                }
                clazz.ENEhitiseOtsing = new System.Collections.Generic.List<ENEhitiseOtsingResponse.IENEhitiseOtsingType>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("EN_EhitiseOtsing");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "ehitised")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>EN_EhitiseOtsing_response>EN_EhitiseOtsing>ehitised");
                        }
                        global::Xtee.Core.SerializationMetadata metaENEhitiseOtsing = this.GetMetaData<ENEhitiseOtsingResponse.IENEhitiseOtsingType>(Reader, ">>>EN_EhitiseOtsing_response>EN_EhitiseOtsing>ehitised", "http://producers.ehr.xtee.riik.ee/producer/ehr");
                        ENEhitiseOtsingResponse.IENEhitiseOtsingType item = metaENEhitiseOtsing.NewEntity<ENEhitiseOtsingResponse.IENEhitiseOtsingType>();
                        clazz.ENEhitiseOtsing.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("ehitised");
                            metaENEhitiseOtsing.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>EN_EhitiseOtsing_response>EN_EhitiseOtsing", Reader.LocalName);
            }
        }
        
        [global::Xtee.Core.Attributes.XmlTypeAttribute(Name=">>>EN_EhitiseOtsing_response>EN_EhitiseOtsing>ehitised", Namespace="http://producers.ehr.xtee.riik.ee/producer/ehr", Target=typeof(ENEhitiseOtsingResponse.ENEhitiseOtsingType))]
        public class ENEhitiseOtsingTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
            
            protected ENEhitiseOtsingResponse.IENEhitiseOtsingType clazz;
            
            public ENEhitiseOtsingTypeSerializer(ENEhitiseOtsingResponse.IENEhitiseOtsingType clazz) {
                this.clazz = clazz;
            }
            
            public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXml(Writer);
                if (clazz.Nimetus!=null) {
                    Writer.WriteStartElement("nimetus");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Nimetus))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.Staatus!=null) {
                    Writer.WriteStartElement("staatus");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Staatus))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.StaatusTxt!=null) {
                    Writer.WriteStartElement("staatus_txt");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.StaatusTxt))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.EsmaneKasutus!=null) {
                    Writer.WriteStartElement("esmane_kasutus");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.EsmaneKasutus))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.KorrusteArv!=null) {
                    Writer.WriteStartElement("korruste_arv");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.KorrusteArv))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.EhitusalunePind!=null) {
                    Writer.WriteStartElement("ehitusalune_pind");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.EhitusalunePind))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.Aadress!=null) {
                    Writer.WriteStartElement("aadress");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Aadress))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.KiliId!=null) {
                    Writer.WriteStartElement("kili_id");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.KiliId))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.KiliIdTxt!=null) {
                    Writer.WriteStartElement("kili_id_txt");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.KiliIdTxt))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.ToimId!=null) {
                    Writer.WriteStartElement("toim_id");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.ToimId))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.EhitisalunePind!=null) {
                    Writer.WriteStartElement("ehitisalune_pind");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.EhitisalunePind))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.AnonEhrBuildingUrl!=null) {
                    Writer.WriteStartElement("anon_ehr_building_url");
                    Writer.WriteTypeAttribute("http://x-tee.riik.ee/xsd/xtee.xsd", "url");
                    Writer.WriteString(clazz.AnonEhrBuildingUrl.ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.Id!=null) {
                    Writer.WriteStartElement("id");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.Id))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.PosToimikus!=null) {
                    Writer.WriteStartElement("pos_toimikus");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.PosToimikus))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.EhrKood!=null) {
                    Writer.WriteStartElement("ehr_kood");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.EhrKood))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.RajatisHoone!=null) {
                    Writer.WriteStartElement("rajatis_hoone");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.RajatisHoone))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.ErHr!=null) {
                    Writer.WriteStartElement("er_hr");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.ErHr))).ToString());
                    Writer.WriteEndElement();
                }
            }
            
            public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXml(Reader);
                if (Reader.LocalName=="nimetus") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_EhitiseOtsing_response>EN_EhitiseOtsing>ehitised>nimetus");
                    }
                    clazz.Nimetus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("nimetus")).Value;
                }
                if (Reader.LocalName=="staatus") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_EhitiseOtsing_response>EN_EhitiseOtsing>ehitised>staatus");
                    }
                    clazz.Staatus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("staatus")).Value;
                }
                if (Reader.LocalName=="staatus_txt") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_EhitiseOtsing_response>EN_EhitiseOtsing>ehitised>staatus_txt");
                    }
                    clazz.StaatusTxt = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("staatus_txt")).Value;
                }
                if (Reader.LocalName=="esmane_kasutus") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_EhitiseOtsing_response>EN_EhitiseOtsing>ehitised>esmane_kasutus");
                    }
                    clazz.EsmaneKasutus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("esmane_kasutus")).Value;
                }
                if (Reader.LocalName=="korruste_arv") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_EhitiseOtsing_response>EN_EhitiseOtsing>ehitised>korruste_arv");
                    }
                    clazz.KorrusteArv = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("korruste_arv")).Value;
                }
                if (Reader.LocalName=="ehitusalune_pind") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_EhitiseOtsing_response>EN_EhitiseOtsing>ehitised>ehitusalune_pind");
                    }
                    clazz.EhitusalunePind = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("ehitusalune_pind")).Value;
                }
                if (Reader.LocalName=="aadress") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_EhitiseOtsing_response>EN_EhitiseOtsing>ehitised>aadress");
                    }
                    clazz.Aadress = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("aadress")).Value;
                }
                if (Reader.LocalName=="kili_id") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_EhitiseOtsing_response>EN_EhitiseOtsing>ehitised>kili_id");
                    }
                    clazz.KiliId = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kili_id")).Value;
                }
                if (Reader.LocalName=="kili_id_txt") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_EhitiseOtsing_response>EN_EhitiseOtsing>ehitised>kili_id_txt");
                    }
                    clazz.KiliIdTxt = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kili_id_txt")).Value;
                }
                if (Reader.LocalName=="toim_id") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_EhitiseOtsing_response>EN_EhitiseOtsing>ehitised>toim_id");
                    }
                    clazz.ToimId = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("toim_id")).Value;
                }
                if (Reader.LocalName=="ehitisalune_pind") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_EhitiseOtsing_response>EN_EhitiseOtsing>ehitised>ehitisalune_pind");
                    }
                    clazz.EhitisalunePind = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("ehitisalune_pind")).Value;
                }
                if (Reader.LocalName=="anon_ehr_building_url") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_EhitiseOtsing_response>EN_EhitiseOtsing>ehitised>anon_ehr_building_url");
                    }
                    clazz.AnonEhrBuildingUrl = new global::Xtee.Riik.Ee.Xsd.Xtee.Url(Reader.ReadElementString("anon_ehr_building_url"));
                }
                if (Reader.LocalName=="id") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_EhitiseOtsing_response>EN_EhitiseOtsing>ehitised>id");
                    }
                    clazz.Id = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("id")).Value;
                }
                if (Reader.LocalName=="pos_toimikus") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_EhitiseOtsing_response>EN_EhitiseOtsing>ehitised>pos_toimikus");
                    }
                    clazz.PosToimikus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("pos_toimikus")).Value;
                }
                if (Reader.LocalName=="ehr_kood") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_EhitiseOtsing_response>EN_EhitiseOtsing>ehitised>ehr_kood");
                    }
                    clazz.EhrKood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("ehr_kood")).Value;
                }
                if (Reader.LocalName=="rajatis_hoone") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_EhitiseOtsing_response>EN_EhitiseOtsing>ehitised>rajatis_hoone");
                    }
                    clazz.RajatisHoone = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("rajatis_hoone")).Value;
                }
                if (Reader.LocalName=="er_hr") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_EhitiseOtsing_response>EN_EhitiseOtsing>ehitised>er_hr");
                    }
                    clazz.ErHr = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("er_hr")).Value;
                }
            }
        }
    }
}
